<?php
require_once "includes/config.php";
if(isset($_REQUEST['wid'])) {
	$wId=$_REQUEST['wid'];
}		
	$id = $wId;
	$userid=$_REQUEST['user'];
	if($userid=="") {
		echo "<font style='color:red;'>Sign in and add it to your wishlist.</font>";
	}
	elseif($id!="" && $userid!="") {			
			$qry="SELECT * FROM tbl_wishlist where item_id='$id' and user_id='$userid'";
			$res=mysql_query($qry);
			if(mysql_num_rows($res) > 0) {			
				echo "Already Added.";
			}
			else {
			    $sqlSelItem="SELECT * FROM tbl_items WHERE item_id='$id'";
				$rstSelItem=mysql_query($sqlSelItem);
				$rowSelItem=mysql_fetch_array($rstSelItem);
				$productId=$rowSelItem['product_id'];	
				
			    $sqlSelProd="SELECT * FROM tbl_product WHERE product_id='$productId'";
				$rstSelProd=mysql_query($sqlSelProd);
				$rowSelProd=mysql_fetch_array($rstSelProd);
				$productName=$rowSelProd['product_name'];	
				$productPrice=$rowSelProd['product_price'];
			    $currentDate=date("Y-m-d");
				$sql="INSERT INTO tbl_wishlist set item_id='$id', user_id='$userid',product_name='$productName', price='$productPrice', wishlist_type=1,status=1, created_date='$currentDate' ";
				$rst=mysql_query($sql);
				if($rst) { echo "Product added to wishlist."; }
				else { echo "<font style='color:red;'>Error on adding to wishlist.</font>"; }
			}							
					
		}	
				
	?>